package com.prodog.gamemodule.fight.fightobj.builder.impl;

import cn.hutool.core.util.IdUtil;
import com.prodog.commonmodule.prop.caculate.factory.ObjPropHandlerFactory;
import com.prodog.commonmodule.prop.entity.ObjProp;
import com.prodog.gamemodule.fight.fightobj.builder.FightObjBuilder;
import com.prodog.gamemodule.fight.fightobj.entity.FightObj;
import com.prodog.gamemodule.fight.fightobj.entity.FightSkill;
import com.prodog.gamemodule.gameworld.monster.entity.Monster;
import com.prodog.gamemodule.gameworld.monster.entity.MonsterProp;
import com.prodog.utils.bean.BeanUtil;
import com.prodog.utils.interfaces.AutowiredBean;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;

@Slf4j
public class MonsterFightObjBuilder implements FightObjBuilder<Monster>, AutowiredBean {
    public MonsterFightObjBuilder() {
        this.autowired();
    }

    @Override
    public FightObj build(Monster monster) {
        MonsterProp prop = monster.getProp();
        FightObj fightObj = new FightObj() {{
            setName(monster.getName());
            setPanelProp(new ObjPropHandlerFactory().getHandler(MonsterProp.class).handle(prop));
            setFightProp(BeanUtil.beanToBean(getPanelProp(), ObjProp.class));
            setUuid(IdUtil.simpleUUID());
            setFlag(1);
            setId(monster.getId());
            if (monster.getId().equals("1")) {
                getSkills().put("1", new FightSkill() {{
                    setId("1");
                    setName("锋刺");
                    setLevel(1);
                    setNormal(true);
                    setDamageType(1);
                    setExpression("parseInt(${obj.physicalAttack} * (${physicalAttackPercent}*0.01))");
                    setProp(new HashMap() {{
                        put("physicalAttackPercent", 120);
                    }});
                }});
                getSkills().put("2", new FightSkill() {{
                    setId("2");
                    setName("飞针");
                    setLevel(1);
                    setNormal(true);
                    setDamageType(1);
                    setConsumeMp(5);
                    setExpression("parseInt(${obj.physicalAttack} * (${physicalAttackPercent}*0.01))");
                    setProp(new HashMap() {{
                        put("physicalAttackPercent", 150);
                    }});
                }});
            }
            if (monster.getId().equals("3")) {
                getSkills().put("3", new FightSkill() {{
                    setId("3");
                    setName("撞击");
                    setLevel(1);
                    setNormal(true);
                    setDamageType(1);
                    setExpression("parseInt(${obj.physicalAttack} * (${physicalAttackPercent}*0.01))");
                    setProp(new HashMap() {{
                        put("physicalAttackPercent", 120);
                    }});
                }});
                getSkills().put("4", new FightSkill() {{
                    setId("4");
                    setName("野蛮冲撞");
                    setLevel(1);
                    setNormal(true);
                    setDamageType(1);
                    setConsumeMp(5);
                    setExpression("parseInt(${obj.physicalAttack} * (${physicalAttackPercent}*0.01))");
                    setProp(new HashMap() {{
                        put("physicalAttackPercent", 150);
                    }});
                }});
            }
            getEffects().addAll(monster.getEffects());
            setFightAi("com.prodog.gamemodule.fight.ai.impl.NormalFightAI");
            //setFightAi(monster.getFightAi());
        }};
        return fightObj;
    }
}
